package routers

import (
	"github.com/gin-gonic/gin"
	"vpn/app/http/controller"
	"vpn/app/http/middleware"
)

func InitApiRouter(mode string) *gin.Engine {
	gin.SetMode(mode)
	var router = gin.Default()

	// 可能会导致需要备案等
	//router.GET("/", func(context *gin.Context) {
	//	context.String(http.StatusOK, "Welcome to vpn-backend!")
	//})

	//  openvpn接口路由组
	openvpn := router.Group("/openvpn/", middleware.AuthJwtToken)
	{
		openvpn.POST("init", controller.InstallOpenvpnService)
		openvpn.POST("reset", controller.ResetOpenvpnService)
		config := openvpn.Group("config/") //authorization.CheckCasbinAuth()
		{

			config.GET("query", controller.GetOpenvpnConfig)
			config.POST("save", controller.SaveOpenConfig)
		}
	}
	// user接口路由组
	user := router.Group("/user/")
	{
		user.POST("login", controller.Login)
		userInfo := user.Group("info/", middleware.AuthJwtToken)

		{
			//userInfo.GET("query", controller.GetUserInfo)
			userInfo.POST("save", controller.SaveUserInfo)
			userInfo.POST("change_pwd", controller.ChangePassWord)
		}
	}
	return router
}
